<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>实验室助理工作管理系统</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
    <meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
    <meta name="author" content="yinqi">
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/css/materialdesignicons.min.css}">
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/css/style.min.css}">
    <!--对话框-->
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/js/jconfirm/jquery-confirm.min.css}">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
</head>
<body>

<!--页面主要内容-->
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header"><h4>设备维修信息列表</h4></div>
            <div class="card-header">
                <div class="form-group">
                    <div class="row">
                        <div class="col-xs-10">
                            <form class="form-inline" action="" >
                                <div class="form-group">
                                    <label class="sr-only" for="example-if-email">搜索</label>
                                    <input class="form-control" type="text" id="example-if-email" name="name" placeholder="search..">
                                </div>
                                <div class="form-group">
                                    <button class="btn btn-default" type="submit">搜索</button>
                                </div>
                            </form>
                        </div>
                        <div class="col-xs-1">
                            <a class="btn btn-yellow m-r-5" href="/SeeRepair"><i class="mdi mdi-refresh"></i>刷新</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="card-body">
                <table class="table table-bordered table-hover">
                    <thead>
                    <tr>
                        <th>报修编号</th>
                        <th>设备编号</th>
                        <th>设备名称</th>
                        <th>维修内容</th>
                        <th>报修人</th>
                        <th>报修时间</th>
                        <th>审核状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="tb_teacher">
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<!--End 页面主要内容-->

<script type="text/javascript" th:src="@{/js/jquery-3.6.0.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/bootstrap.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/perfect-scrollbar.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/main.min.js}"></script>
<!--消息提示-->
<script th:src="@{/Light-Year-Admin/js/bootstrap-notify.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/lightyear.js}"></script>
<!--对话框-->
<script th:src="@{/Light-Year-Admin/js/jconfirm/jquery-confirm.min.js}"></script>
<!-- layui -->
<script type="text/javascript" th:src="@{/layui/layui.js}"></script>

<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //日期时间选择器
        laydate.render({
            elem: '#repairTime'
            ,type: 'datetime'
        });
    });
</script>

<script type="text/javascript">

    $(function () {
        // 查询所有数据
        getLab();
    });

    // 查询所有数据
    function getLab() {
        $.ajax({
                type: "GET",
                url: "/repair/findAll",
                contentType: 'application/json;charset=utf-8', //设置请求头信息
                dataType: "json",
                success: function (result) {
                    let html = "";
                    let repairState = "";
                    for(let i = 0;i<result.length;i++) {
                        if (result[i].repairState == "0") {
                            repairState = "未审核";
                        } else if (result[i].repairState == "1") {
                            repairState = "已审核";
                        }
                    }
                    for(let i = 0;i<result.length;i++){
                        //一次取出teacher下的每一个变量m,并添加到html中
                        html += "<tr>"+
                            "<td>"+result[i].repairId+"</td>"+
                            "<td>"+result[i].equipmentId+"</td>"+
                            '<td>'+result[i].equipmentName+"</td>"+
                            "<td>"+result[i].repairContent+"</td>"+
                            "<td>"+result[i].repairman+"</td>"+
                            "<td>"+result[i].repairTime+"</td>"+
                            "<td>"+repairState+"</td>"+
                            '<td>'+'<a class="btn btn-primary btn-sm" role="button" href="javascript:print(\''+result[i].repairId+'\')"><i class="mdi mdi-cloud-print-outline"></i>打印</a>'+'</td>'
                            +"</tr>";
                    }
                    //将html标签拼接在html中
                    $("#tb_teacher").html(html);
                }
            }
        )
    }


    function print(repairId){
        window.location.href ="/repair/print?repairId=" + repairId
    }
</script>
</body>
</html>